package com.topnav.mc.document.dao.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.topnav.mc.base.mc.McMapper;
import com.topnav.mc.document.bean.DocumentStatisticsBean;
import com.topnav.mc.document.entity.Document;
import com.topnav.mc.document.entity.bean.DocumentBean;
import com.topnav.mc.document.entity.param.DocumentParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface DocumentMapper extends McMapper<Document, DocumentBean, DocumentParam> {
    String commSql = " SELECT d.*, " +
            " s.code AS siteCode, s.name AS siteName,s.host AS siteHost,s.port AS sitePort, s.url AS siteUrl, " +
            " o.code AS orgCode, o.name AS orgName, o.short_name AS shortName, o.path," +
            " u.code AS userCode, u.name AS userName," +
            " dev.code AS deviceCode, u.name AS deviceName " +
            " FROM mc_document d " +
            " LEFT JOIN mc_site s ON d.site_id = s.id " +
            " LEFT JOIN mc_organization o ON d.org_id = o.id " +
            " LEFT JOIN mc_user u ON d.user_id = u.id " +
            " LEFT JOIN mc_device dev ON d.device_id = dev.id " +
            " ${ew.customSqlSegment}";

    @Select(commSql)
    DocumentBean selectInfoOne(@Param(Constants.WRAPPER) Wrapper queryWrapper);

    @Select(commSql)
    List<DocumentBean> selectInfoList(@Param(Constants.WRAPPER) Wrapper queryWrapper);

    @Select(commSql)
    Page<DocumentBean> selectInfoPage(Page<DocumentParam> page, @Param(Constants.WRAPPER) Wrapper queryWrapper);


    /** 自定义分页查询 */
    IPage<Document> searchDocument(Page<?> page, @Param("doc") Document document);

    DocumentStatisticsBean statisticsDocument(@Param("dateBegin") Date dateBegin,@Param("dateEnd")Date dateEnd);
}
